package com.wac.blog.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wac.blog.pojo.Blog;
import com.wac.blog.pojo.BlogCategory;
import com.wac.blog.service.BlogCategoryService;
import com.wac.blog.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Locale;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wac
 * @since 2020-08-04
 */
@Controller
@RequestMapping("/blogcategory")
public class BlogCategoryController {
    @Autowired
    BlogService blogService;

    @Autowired
    BlogCategoryService blogCategoryService;

    @RequestMapping("/{cid}")
    public String blogcategory(@PathVariable Integer cid, Model model){
        Page<Blog> page = new Page<>(1,10);
        blogService.page(page, new QueryWrapper<Blog>().eq("category_id", cid).orderByDesc("gmt_create"));
        List<Blog> blogList = page.getRecords();
        model.addAttribute("blogList", blogList);
        model.addAttribute("page",page );
        List<BlogCategory> blogCategoryList = blogCategoryService.list(null);
        model.addAttribute("blogCategoryList",blogCategoryList );
        BlogCategory category = blogCategoryService.getOne(new QueryWrapper<BlogCategory>().eq("id", cid));
        model.addAttribute("thisCategoryName", category.getCategory());
        return "blog/list";
    }

}

